#ifndef _CAMERA_H_
#define _CAMERA_H_

#include "engine.h"
#include "entity/object3D.h"

namespace engine
{

    class Camera : public Object3D
    {
    public:
        typedef std::shared_ptr<Camera> ptr;

    public:
        Camera()
            : target(glm::vec3(0.0f, 0.0f, 0.0f)), front(glm::vec3(0.0f, 0.0f, -1.0f))
        {
        }

        ~Camera() {}

        glm::mat4 getViewMatrix()
        {
            glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);                                          //世界坐标的上向量
            glm::mat4 trans = glm::mat4(1.0f);                                                   //单位阵
            trans = glm::rotate(trans, glm::radians(this->Rotate.x), glm::vec3(1.0, 0.0, 0.0)); //x
            trans = glm::rotate(trans, glm::radians(this->Rotate.y), glm::vec3(0.0, 1.0, 0.0)); //y
            trans = glm::rotate(trans, glm::radians(this->Rotate.z), glm::vec3(0.0, 0.0, 1.0)); //z
            this->front = glm::vec3(trans * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f));
            // return glm::lookAt(this->position, this->target, up); //定点相机
            return glm::lookAt(this->Position, this->Position + this->front, up);
        }

    protected:
        glm::vec3 target; //定点摄像机
        glm::vec3 front;  //前视相机

        // glm::vec3 getUpVector()
        // {
        //     glm::vec3 direction = glm::normalize(this->position - this->target);
        //     glm::vec3 cameraRight = glm::normalize(glm::cross(up, cameraDirection);
        //     glm::vec3 cameraUp = glm::cross(cameraDirection, cameraRight);
        //     return cameraUp;
        // }
    };

}
#endif